package hongcaosp.app.android.comment;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import hongcaosp.app.android.R;
import hongcaosp.app.android.common.BaseAdapter;
import hongcaosp.app.android.common.BaseHolder;
import xlj.lib.android.base.view.OnRecycleItemClickListener;

public class CommentAdapter extends BaseAdapter<IViewType> {
    private Context context;

    private OnRecycleItemClickListener onRecycleItemClickListener;
    private CommentGoodListener commentGoodListner;

    public CommentAdapter(Context context, OnRecycleItemClickListener onRecycleItemClickListener,
                          CommentGoodListener commentGoodListner) {
        this.context = context;
        this.onRecycleItemClickListener = onRecycleItemClickListener;
        this.commentGoodListner = commentGoodListner;
    }

    @NonNull
    @Override
    public BaseHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == IViewType.VIEWTYPE_COMMENT) {
            CommentHolder ch = new CommentHolder(context,LayoutInflater.from(context).inflate(R.layout.item_comment,parent,false),onRecycleItemClickListener);
            ch.setCommentGoodListner(commentGoodListner);
            return ch;
        } else if (viewType == IViewType.VIEWTYPE_COMMENT_REPLY) {
            CommentReplyHolder crh = new CommentReplyHolder(context,LayoutInflater.from(context).inflate(R.layout.item_comment_reply,parent,false),
                    onRecycleItemClickListener);
            crh.setCommentGoodListner(commentGoodListner);
            return crh;
        } else if (viewType == IViewType.VIEWTYPE_COMMENT_RANGE) {
            return new CommentRangeHolder(LayoutInflater.from(context).inflate(R.layout.item_comment_range, parent, false), onRecycleItemClickListener);
        }
        return null;
    }

    @Override
    public int getItemViewType(int position) {
        IViewType viewType = getItem(position);
        return viewType.viewType();
    }
}
